<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="w" %>
<style>
    .classpro {
        display: none;
    }

    #errormsg {
        position: fixed;
        width: 200px;
        height: 50px;
        line-height: 50px;
        padding: 1px 5px;
        text-align: center;
        background-color: #00A4F2;
        opacity: 0.5;
        color: #fff;
        left: 50%;
        margin-left: -50px;
        top: 50%;
        border-radius: 20px;
        z-index: 100000000;
    }
    .ui_td td{
        background:#ffffff;
        color:#797979;
        height:25px;
        font-size:14px;
        border-bottom:1px solid #EEEEEE;
        padding-left:3px;
        cursor: pointer;
    }
</style>
<div data-options="region:'center'" class="bodybg">
    <!-- 查询区域 -->
    <form id="dataForm" action="/marketing/FillReductionPage@chooseMoneyList.page" method="post">
        <w:hidden bind="bean.id"/>
        <script>
            function selectAll(obj) {
                if (obj.checked) {
                    $("#tbody_tr_list tr[proid]").each(function (i, n) {
                        this.checked = true;
                        var proId = $(this).attr("proid");
                        var tempProductItems = {};
                        var tempProductItemTo = {};
                        tempProductItemTo.showlistidto = $(this).find("input[name='showlistid']").val();

                        tempProductItems.showlistname = $(this).find("input[name='showlistname']").val();
                        tempProductItems.showlistid = $(this).find("input[name='showlistid']").val();
                        tempProductItems.price = $(this).find("input[name='price']").val();
                        tempProductItems.showlistcode = $(this).find("input[name='showlistcode']").val();
                        tempProductItems.showlistB_chanjia = $(this).find("input[name='showlistB_chanjia']").val();
                        tempProductItems.showlistB_guige = $(this).find("input[name='showlistB_guige']").val();
                        tempProductItems.showlistclassname = $(this).find("input[name='showlistclassname']").val();
                        tempProductItems.showlistproductamount = $(this).find("input[name='showlistproductamount']").val();
                        tempProductItems.showlisttypes = $(this).find("input[name='showlisttypes']").val();

                        // 添加到列表对象
                        productItems["key" + tempProductItems.showlistid] = tempProductItems;
                        productItemsTo["key" + tempProductItemTo.showlistidto] = tempProductItemTo;
                        $(this).find("input[name='primaryKey_']").prop("checked", true);
                        if ($(this).find("input[name='primaryKey_']").attr("class") != "cur") {
                            $(this).find("input[name='primaryKey_']").toggleClass("cur");
                        }

                    });
                } else {
                    $("#tbody_tr_list tr[proid]").each(function (i, n) {
                        var proId = $(this).attr("proid");
                        // 从列表对象移除
                        delete productItems["key" + proId];
                        delete productItemsTo["key" + proId];
                        $(this).find("input[name='primaryKey_']").prop("checked", false);

                    });
                }
            }


            /*点击查看全部商品切换*/
            $.fn.toggle = function (fn) {
                var args = arguments,
                    guid = fn.guid || jQuery.guid++,
                    i = 0,
                    toggler = function (event) {
                        var lastToggle = ( jQuery._data(this, "lastToggle" + fn.guid) || 0 ) % i;
                        jQuery._data(this, "lastToggle" + fn.guid, lastToggle + 1);
                        event.preventDefault();
                        return args[lastToggle].apply(this, arguments) || false;
                    };
                toggler.guid = guid;
                while (i < args.length) {
                    args[i++].guid = guid;
                }
                return this.click(toggler);
            }

            $(function () {
                $("#see").toggle(
                    function () {
                        $("#seetab").hide();
                        $(".ui-pagination").hide();
                        $("#see").css("background-color", " #C9C9C9");
                        $("#seestab").show();

                    },
                    function () {
                        $("#seetab").show();
                        $(".ui-pagination").show();
                        $("#see").removeAttr("style")
                        $("#seestab").hide();
                    }
                )
            })
            //var productItems = {};
            function inp(obj) {

                $(obj).toggleClass("cur");


                //获取商品属性
                var productPromot = $(obj).parents("tr");
                if (productPromot && productPromot.find("input[name='showlistid']").val()) {

                    var tempProductItem = {};
                    var tempProductItemTo = {};

                    tempProductItemTo.showlistidto = productPromot.find("input[name='showlistid']").val();

                    tempProductItem.showlistid = productPromot.find("input[name='showlistid']").val();
                    tempProductItem.price = productPromot.find("input[name='price']").val();
                    tempProductItem.showlistname = productPromot.find("input[name='showlistname']").val();
                    tempProductItem.showlistcode = productPromot.find("input[name='showlistcode']").val();
                    tempProductItem.showlistB_chanjia = productPromot.find("input[name='showlistB_chanjia']").val();
                    tempProductItem.showlistB_guige = productPromot.find("input[name='showlistB_guige']").val();
                    tempProductItem.showlistclassname = productPromot.find("input[name='showlistclassname']").val();
                    tempProductItem.showlistproductamount = productPromot.find("input[name='showlistproductamount']").val();
                    tempProductItem.showlisttypes = productPromot.find("input[name='showlisttypes']").val();

                    productItems["key" + tempProductItem.showlistid] = tempProductItem;
                    productItemsTo["key" + tempProductItemTo.showlistidto] = tempProductItemTo;
                    console.log(productItems)

                }

                if (productItems) {
                    $("#pro").find("tr").remove();
                    for (var productItemKey in productItems) {
                        var productItem = productItems[productItemKey];
                        if (productItem['showlistid'] != null) {
                            if (productItem) {
                                $("#pro").append("<tr class='ui_td'>" +
                                    "<td>" + productItem['showlistcode'] + "</td>" +
                                    "<td>" + productItem["showlistname"] + "</td>" +
                                    "<td>" + productItem["price"] + "</td>" +
                                    "<td>" + productItem["showlistB_chanjia"] + "</td>" +
                                    "<td>" + productItem["showlistB_guige"] + "</td>" +
                                    "<td>" + productItem["showlistclassname"] + "</td>" +
                                    "<td>" + productItem["showlistproductamount"] + "</td>" +
                                    "<td>" + productItem['showlisttypes'] + "</td>" +
                                    " <td style='text-align:center;'><span onclick='deletepro(" + productItem['showlistid'] + ")' id='single" + productItem['showlistid'] + "' style='color: #00ADFF'>删除</span></td>" +
                                    "</tr>");
                            }
                        }

                        }
                    }
                 console.log($(obj).hasClass("cur"));
                 if ($(obj).hasClass("cur") == false) {
                    delete productItems["key" + productPromot.find("input[name='showlistid']").val()];
                    delete productItemsTo["key" + productPromot.find("input[name='showlistid']").val()];
                 }

            }
            function deletepro(id) {
                delete productItems["key" + id];
                delete productItemsTo["key" + id];
                $("#single" + id).parents("tr").remove();
                $("tr[proid=" + id + "]").find(".cur").prop("checked", false).removeClass("cur");
            }
        </script>
        <div class="ui_line" style="margin-top:10px"></div>
        <w:hidden bind="pageSize_" value="10"/>
        <w:hidden bind="pageNum" value="1"/>
        <w:hidden bind="bean.code"/>
        <w:hidden bind="bean.pname"/>
        <w:hidden bind="bean.classid"/>
        <!-- 数据列表区域 -->
        <div style="border: 1px solid #DDDDDD;" id="seetab">
            <table class="ui-table" width="100%" id="saleattrstb" cellpadding="1" cellspacing="1" data-options="showPage:true,
																							pageNum:<w:write bind="pageNum" />,
																							pageSize:<w:write bind="10"/>,
																							total:<w:write bind="pagination.totalCount"/>,form:'dataForm'">
                <thead>
                <tr class="ui_th">
                    <td width="40">商品编码</td>
                    <td width="100">商品名称</td>
                    <td width="100">原价</td>
                    <td width="160">生产厂家</td>
                    <td width="160">规格</td>
                    <td width="160">商品分类</td>
                    <td width="80">库存</td>
                    <td width="80">促销类型</td>
                    <td width="80">操作<input type="checkbox" onclick="selectAll(this)"></td>
                </tr>
                </thead>
                <tbody id="tbody_tr_list">
                <w:iterate id="info" bind="resultList_">
                    <w:define id="info_product_type_money_off" bind="#info.product_type_money_off"></w:define>
                    <w:switch>
                        <w:case bind="#info_product_type_money_off == null ">
                            <tr proid="<w:write bind="#info.id"/>" class="ui_td">
                                <input type="hidden" name="showlistname" value="<w:write bind="#info.pname"/>">
                                <input type="hidden" name="showlistid" value="<w:write bind="#info.id"/>">
                                <input type="hidden" name="showlistcode" value="<w:write bind="#info.code"/>">
                                <input type="hidden" name="showlistB_chanjia" value="<w:write bind="#info.B_chanjia"/>">
                                <input type="hidden" name="showlistB_guige" value="<w:write bind="#info.B_guige"/>">
                                <input type="hidden" name="showlistclassname" value="<w:write bind="#info.classname"/>">
                                <input type="hidden" name="price" value="<w:write bind="#info.price"/>">
                                <input type="hidden" name="showlistproductamount"
                                       value="<w:write bind="#info.productamount"/>">
                                <input type="hidden" name="showlisttypes" value="<w:write bind="#info.moneyofftype"/>">
                                <input type="hidden" name="productSingle" value="<w:write bind="#productSingle"/>">
                                <input type="hidden" name="classname" value="<w:write bind="#classname"/>">
                                <td><w:write bind="#info.code"/></td>
                                <td><w:write bind="#info.pname"/></td>
                                <td><w:write bind="#info.price"/></td>
                                <td><w:write bind="#info.B_chanjia"/></td>
                                <td><w:write bind="#info.B_guige"/></td>
                                <td><w:write bind="#info.classname"/></td>
                                <w:define id="info_productamount" bind="#info.productamount"></w:define>
                                <w:switch>
                                    <w:case bind="#info_productamount <100">
                                        <td style="color: red"><w:write bind="#info.productamount"/></td>
                                    </w:case>
                                    <w:case bind="#info_productamount >= 100">
                                        <td><w:write bind="#info.productamount"/></td>
                                    </w:case>
                                </w:switch>
                                <td><w:write bind="#info.moneyofftype"/></td>
                                <td align="center"><input type="checkbox" name="primaryKey_" onclick="inp(this)"
                                                          value="<w:write bind="#info.id"/>"></td>
                            </tr>
                        </w:case>
                        <w:case bind="#info_product_type_money_off != null ">
                            <tr class="ui_td">
                                <td><w:write bind="#info.code"/></td>
                                <td><w:write bind="#info.pname"/></td>
                                <td><w:write bind="#info.price"/></td>
                                <td><w:write bind="#info.B_chanjia"/></td>
                                <td><w:write bind="#info.B_guige"/></td>
                                <td><w:write bind="#info.classname"/></td>
                                <td><w:write bind="#info.productamount"/></td>
                                <td><w:write bind="#info.moneyofftype"/></td>
                                <td align="center"><w:write bind='#info_product_type_money_off'/></td>
                            </tr>
                        </w:case>
                    </w:switch>

                </w:iterate>
                </tbody>
            </table>
        </div>
        <div id="seestab" style="border: 1px solid #DDDDDD;display: none;">
            <table class="ui-table" width="100%" cellpadding="1" cellspacing="1" data-options="showPage:false">
                <thead>
                <tr class="ui_th">
                    <td width="40">商品编码</td>
                    <td width="100">商品名称</td>
                    <td width="100">原价</td>
                    <td width="160">生产厂家</td>
                    <td width="160">规格</td>
                    <td width="160">商品分类</td>
                    <td width="80">库存</td>
                    <td width="80">促销类型</td>
                    <td width="80">操作</td>
                </tr>
                </thead>
                <tbody id="pro">

                </tbody>
            </table>
        </div>
    </form>
</div>


